package prueba.principal.util;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class CheckSession {
	
	private static final long TIMEOUT=300*1000;

	public static boolean sessionValid(){
		
		HttpSession sesion =(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);		
		long tiempoCreacion=sesion.getCreationTime();
		
		if(System.currentTimeMillis()-tiempoCreacion>TIMEOUT){		
			
			return false;
		}
		
		return true;
	}
	
	public static String sessionSecondsLeft(){
		
		
		
		
		HttpSession sesion =(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);		
		long tiempoCreacion=sesion.getCreationTime();
		long valor=TIMEOUT-(System.currentTimeMillis()-tiempoCreacion);
		valor/=1000;
		
		
		return valor+" secs left.";
		
		
	}
	
}
